#include "ann.h"

ANN::ANN()
{
}

void ANN::createANN(int inputNum, int hiddenNum, int outputNum)
{
    params.train_method=CvANN_MLP_TrainParams::BACKPROP;
    params.bp_dw_scale=0.1;
    params.bp_moment_scale=0.1;
    cv::Mat layerSizes=(cv::Mat_<int>(1,5) << inputNum,
                        hiddenNum,hiddenNum,hiddenNum,
                        outputNum);   //22个
    bp.create(layerSizes,CvANN_MLP::SIGMOID_SYM);
}

void ANN::trainANN(std::vector<std::vector<double> > &data, std::vector<int> &label)
{
    cv::Mat trainingDataMat((int)data.size(), inputNum, CV_32FC1, 0);
    cv::Mat labelsMat((int)label.size(),inputNum,CV_32FC1,0);

    for(int i = 0; i < (int)data.size(); ++i) {
        for(int j = 0; j < (int)data[i].size(); ++j) {
            trainingDataMat.at<double>(i,j) = data[i][j];
            labelsMat.at<double>(i,j) = label[i];
        }
    }
    std::cout<<"Processing..."<<std::endl;
    bp.train(trainingDataMat, labelsMat, cv::Mat(),cv::Mat(), params);
    std::cout<<"Done."<<std::endl;
}

void ANN::ANNPredict()
{

}
